package gameEntities;

import player.Player;
import sound.SoundGenerator;

/**
 * The Class BaitFishCollider checks if there is any fish that collides with the bait.
 */
public class BaitFishCollider {
	
	/**
	 * Checks if any fish collides with the bait.
	 *
	 * @param gem the game entity manager
	 * @param bait the bait
	 * @param player the player
	 * @param soundGenerator the sound generator
	 */
	public static void Collide(GameEntityManager gem, Bait bait, Player player, SoundGenerator soundGenerator) {
		GameEntity[] ge = gem.GetEntities();
		for(int i = 0;i < ge.length;i++) {
			if (ge[i] instanceof Fish && ge[i].Collides(bait)) {
				if (ge[i] instanceof Shark) {
					player.Kill();
				} else {
					if(!((Fish)ge[i]).isFlashed()) {
						((Fish)ge[i]).flashAndKill();		//starts flash animation which kills the gameEntity
						player.AddTime(((Fish)ge[i]).GetTimeBonus());
						soundGenerator.playFlashSound();
					}
				}
			}
		}
	}
}
